<?php

namespace common\models\myhtsq;

use common\models\BaseModel;

/**
 * Description of InvoiceModel
 * 发票信息统一model
 * @author chenxc
 */
class InvoiceModel extends BaseModel {

    public $invoice_id;
    public $invoice_category;
    public $invoice_type;
    public $is_main_invoice;
    public $invoice_code;
    public $invoice_no;
    public $proposer_id;
    public $invoice_date;
    public $invoice_amount;
    public $customer_name;
    public $invoice_company_id;
    public $is_child_invoice;
    public $main_invoice_id;
    public $invoice_status;
    public $contract_id;
    public $receivables_amount;
    public $payment_amount;
    public $is_red_invoice;
    public $red_by_invoice_id;
    public $is_lose;
    public $is_receipt;
    public $invoice_begin_date;
    public $invoice_end_date;
    public $remark;
    public $created_on;
    public $created_by;
    public $modified_on;
    public $modified_by;
    public $searchKey;
    public $pageIndex;
    public $pageSize;
    public $is_reded_invoice;

    /**
     * @var int 是否接口同步过来的
     */
    public $is_sync;

    /**
     * 发票摘要model(这里是一个数组)
     * @var [\common\models\myhtsq\InvoiceSummaryModel]
     */
    public $invoiceSummarys;

    /**
     * 发票关联的应收款model(这里是一个数组)
     * @var [\common\models\myhtsq\InvoiceReceivableModel] 
     */
    public $invoiceReceivables;
    
    /**
     * 发票关联的文档信息
     * @var [\common\models\myhtsq\DocumentModel]  
     */
    public $invoiceDocuments;

    /**
     * @var int 标记发票数据来源 0:发票管理新增发票 1:发票管理发票导入 2:合同管理新增发票 3:ekp收据转发票 4:ekp新增发票 5:合同管理收据转发票
     */
    public $is_import;

    public function __construct($config = array()) {
        parent::__construct($config);
    }

    public function rules() {
        return [
            // 获取发票列表
            [['is_main_invoice'], 'integer', 'on' => 'getinvoicelistbypage'],
            [['is_main_invoice'], 'default', 'value' => -1, 'on' => 'getinvoicelistbypage'],
            [['invoice_status'], 'integer', 'on' => 'getinvoicelistbypage'],
            [['invoice_status'], 'default', 'value' => -1, 'on' => 'getinvoicelistbypage'],
            [['invoice_begin_date', "invoice_end_date"], 'date', 'format' => 'php:Y-m-d', 'on' => 'getinvoicelistbypage'],
            [['searchKey'], 'string', 'on' => 'getinvoicelistbypage'],
            [['pageIndex'], 'integer', 'min' => 1, 'on' => 'getinvoicelistbypage'],
            [['pageIndex'], 'default', 'value' => 1, 'on' => 'getinvoicelistbypage'],
            [['pageSize'], 'integer', 'min' => 1, 'on' => 'getinvoicelistbypage'],
            [['pageSize'], 'default', 'value' => 20, 'on' => 'getinvoicelistbypage'],
            // 保存发票
            [['invoice_category', 'is_main_invoice', 'invoice_status', 'is_red_invoice', 'is_lose', 'is_child_invoice', 'is_receipt', 'invoice_type', 'is_reded_invoice'], 'integer', 'on' => 'saveinvoice'],
            [['invoice_category', 'is_main_invoice', 'invoice_status', 'is_red_invoice', 'is_lose', 'is_child_invoice', 'is_receipt', 'invoice_type', 'is_reded_invoice'], 'default', 'value' => 0, 'on' => 'saveinvoice'],
            [['invoice_date', 'created_on', 'modified_on', 'remark'], 'safe', 'on' => 'saveinvoice'],
            [['invoice_amount', 'receivables_amount', 'payment_amount'], 'number', 'on' => 'saveinvoice'],
            [['invoice_amount', 'receivables_amount', 'payment_amount'], 'default', 'value' => 0, 'on' => 'saveinvoice'],
            [['proposer_id', 'invoice_company_id', 'main_invoice_id', 'contract_id', 'invoice_id','red_by_invoice_id'], 'string', 'max' => 36, 'on' => 'saveinvoice'],
            [['invoice_code', 'invoice_no'], 'string', 'max' => 50, 'on' => 'saveinvoice'],
            [['customer_name'], 'string', 'max' => 100, 'on' => 'saveinvoice'],
            [['invoiceSummarys'], 'safe', 'on' => 'saveinvoice'],
            [['invoiceReceivables'], 'safe', 'on' => 'saveinvoice'],
            [['invoiceDocuments'], 'safe', 'on' => 'saveinvoice']
        ];
    }

}
